package com.yuchen.jaxrs.restclient;

import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;

/**
 *
 */
public abstract class RestEasyClientTemplate {

    public Object process(String url) {
        ResteasyClient client = null;
        ResteasyWebTarget target = null;
        try {
            client = openClient();
            target = client.target(url);
           return doProcess(target);
        } catch (Exception e) {
            throw new RestClientException(e);
        } finally {
            if(client!=null) client.close();
        }

    }


    protected abstract Object doProcess(ResteasyWebTarget target);

    private static ResteasyClient openClient() {
        return new ResteasyClientBuilder().build();
    }
}
